<template>
	<view class="">
		<headerinfo></headerinfo>
		<!-- <headertop :inv="3"></headertop> -->
		<view class="content">
			<!-- <u-icon name="home" size="23" @click="$Show.backHome()" v-if="type" class="backimg"></u-icon>
			<u-icon name="arrow-left" size="20" @click="$Show.backPage()" v-else class="backimg"></u-icon> -->
			<image @click="back" src="@/static/images/backimg.png" mode="" class="backimg"></image>
			<dt-video ref="dtvideo" @share="share"></dt-video>
			<uni-popup ref="popup" type="bottom">
				<share @closeDia="closeDia"></share>
			</uni-popup>
			
			<!-- 
			<uni-popup ref="popup2" type="bottom">
				<pinglun @changeShow="changeShow" ref="pinglun" @send="getcommentlistbyactivityid" @closeDia2="closeDia2"
					:activity_id="activity_id" ></pinglun>
			</uni-popup>
			-->
		</view>
	</view>
	
</template>

<script>
	import share from '@/components/share/share.vue'
	import dtVideo from "@/components/dt-video/dt-video"
	export default {
		components: {
			dtVideo,share
		},
		data() {
			return {
				videos: [],
				type:''
			}
		},
		onLoad(option) {
			if(option.data){
				let str = decodeURIComponent(option.data)
				this.videos = JSON.parse(str)
				this.$nextTick(()=>{
					this.$refs.dtvideo.init(this.videos)
				})
				console.log(this.videos)
			}
			
			if(option.type){
				this.type = option.type
			}

		},
		onShow() {
			wx.showShareMenu({
				withShareTicket: true,
				//设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
				menus: ["shareAppMessage", "shareTimeline"]
			})
		},
		methods: {
			back() {
				if(this.type == 2){
					uni.reLaunch({
						url:'/pages/tabbar/index/index'
					})
				}else{
					uni.navigateBack()
				}
			},
			share() {
				this.$refs.popup.open('bottom')
			},
			closeDia() {
				this.$refs.popup.close()
			},
			// 分享到朋友圈
			onShareTimeline(options) {
				
				let datas = encodeURIComponent(JSON.stringify(this.videos))
				let that = this
				let data = {
					title: '您的好友分享了一个视频', // 默认是小程序的名称
					path: `/pages/tabbar/video/videoInfo?type=2&data=${datas}`, // 页面路径，默认是当前页面，必须是以‘/’开头的完整路径
					imageUrl: '', // 图片封面，本地文件路径、网络图片路，支持PNG及JPG，默认当前页面截图，显示图片长宽比是 5:4。
					success: res => {
						// 分享成功
						if (res.errMsg == 'shareAppMessage:ok') {}
					},
					fail: res => {
						// 用户取消
						if (res.errMsg == 'shareAppMessage:fail cancel') {}
						// 分享失败
						if (res.errMsg == 'shareAppMessage:fail') {}
					},
					complete: res => {}
				}
				return data
			},
			// 分享给好友
			onShareAppMessage(options) {
				
				let datas = encodeURIComponent(JSON.stringify(this.videos))
				console.log(datas)
				var that = this;
				// 设置菜单中的转发按钮触发转发事件时的转发内容
				var shareObj = {
					title: '您的好友分享了一个视频', // 默认是小程序的名称(可以写slogan等)
					desc: '', // 小程序的描述
					path: `/pages/tabbar/video/videoInfo?type=2&data=${datas}`, // 默认是当前页面，必须是以‘/’开头的完整路径
					imageUrl: '', // 图片封面，本地文件路径、网络图片路，支持PNG及JPG，默认当前页面截图，显示图片长宽比是 5:4。
					success: function(res) {
						// 转发成功之后的回调
			
						if (res.errMsg == 'shareAppMessage:ok') {
							console.log(res)
			
						}
					},
					
				}
				
				// 返回shareObj
				return shareObj;
			},

		}
	}
</script>

<style lang="scss">
	.content{
		width: 500px;
		margin: 0 auto;
	}
	.backimg {
		position: fixed;
		z-index: 100000000;
		top: 140px;
		width: 100rpx;
		height: 100rpx;
		padding: 20rpx;
		box-sizing: border-box;
		left: 32%;
		cursor: pointer;
		z-index: 100;
	}
</style>